import time
from wordpress_project.base.base_page import Tools
from selenium import webdriver


class reg_tool(Tools):
    """页面元素定位"""
    reg_url = "http://192.168.0.125:9009/wp-login.php?action=register"
    username_reg = '[id="user_login"]'  # 用户名css定位
    email_ref = '[id="user_email"]'   # 电子邮件css定位
    reg_button_ele = '[id="wp-submit"]'  # 注册按钮css定位
    reg_success_ele = '[id="login"]'  # 注册成功之后的断言定位
    reg_fail_ele = '[id="login_error"]'  # 注册失败之后的断言定位

    def reg_action(self, username, email):
        self.visit(self.reg_url)
        self.by_css(self.username_reg).send_keys(username)
        time.sleep(0.5)
        self.by_css(self.email_ref).send_keys(email)
        time.sleep(0.5)
        self.by_css(self.reg_button_ele).click()
        time.sleep(0.5)
        self.img()

    def get_reg_success(self):
        return self.by_css(self.reg_success_ele).text

    def get_reg_fail(self):
        return self.by_css(self.reg_fail_ele).text


# d = webdriver.Chrome()
# a = reg_tool(driver=d)
# a.reg_action(username='zhangsan', email='12345@qq.com')
# time.sleep(5)
# a.quit()
